/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package UIDebugger;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.awt.geom.Rectangle2D;
import java.net.URL;
import java.util.Vector;

/**
 *
 * @author spok
 */
public class GamePanel extends javax.swing.JPanel {
    private Component gameFrame;

    
    Vector <ScreenElement> elementi;
    Vector <Image> immagini;        
    public GamePanel()
    {
       super();
       elementi = new Vector <ScreenElement> ();
    }
    
    private void initComponents() {
        
                
    }

    public void viewOutput(Vector <ScreenElement> elems)
{ 
    MediaTracker tracker=new MediaTracker(this);
    elementi  = elems;
    immagini = new Vector <Image> ();
    for(ScreenElement e: elems)
    {
      
        try
        {
     e.s.i=   Toolkit.getDefaultToolkit().getImage(
             new URL("http://127.0.0.1/res/"+e.s.filename)
             );
        }catch(Exception ex)
        {
            System.out.println("malformend: "+e.s.filename);   
        }
     tracker.addImage(e.s.i,0);

     try{ tracker.checkID(0); }
     catch (Exception ex){
        System.out.println("error loading: "+e.s.filename);  
     }
    }
    repaint();
    }
    
    @Override
    public void repaint()
    {
     super.repaint();
    }
    
    public void paintComponent(Graphics g)
    {
          
         super.paintComponent(g);

         Graphics2D g2 = (Graphics2D) g;
         

        for(ScreenElement e:elementi)
        {
         Rectangle2D r  = new Rectangle2D.Double
                 (
                    (double)e.position.x,
                    (double)e.position.y,
                    (double)e.position.width,
                    (double)e.position.height
                 );
         
 
         g2.draw(r);
              g.drawImage(e.s.i ,e.position.x,e.position.y,null);
     
        }
    }
}
